
import CommunityAPI from '../api/community.js';

export const Community={
   state:{
      communitylist:[],
      community_total_count:0,
      editCommunityStatus:-1,     //插入状态 0失败  1成功  -1不改变
      communityinfo:[],
      delCommunityStatus:-1,       //删除状态
      allcommunitylist:[]
   },
   mutations:{
      setCommunityList(state,list){
          state.communitylist=list;
      },
      setCommunityTotalCount(state,total_count){
          state.community_total_count=total_count;
      },
      setEditCommunityStatus(state,status){
          state.editCommunityStatus=status;
      },
      setCommunityInfo(state,info){
          state.communityinfo=info;
      },
      setDelCommunityStatus(state,status){
          state.delCommunityStatus=status;
      },
      setAllCommunityList(state,list){
          state.allcommunitylist=list;
      }
   },
   actions:{
      loadCommunityList(context,data){
          CommunityAPI.getCommunityList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setCommunityList',response.data.list);
                  context.commit('setCommunityTotalCount',response.data.total_count);
              }
          })
      },
      //插入Community
      editCommunity(context,data){
          CommunityAPI.editCommunity(data).then(function(response){
              context.commit('setEditCommunityStatus',response.data.code);
          })
      },
      //获取详情
      loadCommunityInfo(context,data){
          CommunityAPI.getCommunityInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setCommunityInfo',response.data.info);
              }
          })
      },
      //删除
      delCommunity(context,data){
          CommunityAPI.delCommunity(data).then(function(response){
                context.commit('setDelCommunityStatus',response.data.code);
          })
      },
      loadAllCommunityList(context,data){
          CommunityAPI.getAllCommunityList(data).then(function(response){
                context.commit('setAllCommunityList',response.data.list);
          })
      }
   },
   getters:{
      getCommunityList:state =>{
         return state.communitylist
      },
      getCommunityTotalCount: state =>{
         return state.community_total_count
      },
      getEditCommunityStatus:state=>{
          return state.editCommunityStatus;
      },
      getCommunityInfo:state => {
          return state.communityinfo;
      },
      getDelCommunityStatus:state => {
          return state.delCommunityStatus;
      },
      getAllCommunityList:state =>{
          return state.allcommunitylist;
      }
   }
}
